package com.zhong.beautifulimageapp.utils;

import android.content.Intent;
import android.support.v4.app.Fragment;

import com.zhong.beautifulimageapp.MyActivity;
import com.zhong.beautifulimageapp.fragments.ui.TopicDetailActivity;
import com.zhong.beautifulimageapp.model.EventBusMessageAboutTopicID;
import com.zhong.beautifulimageapp.model.EventBusMessageAboutUserName;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

/**
 * 基础的fragment
 * Created by 俊峰 on 2017/7/10.
 */

public abstract class BaseFragments extends Fragment {

    /**
     * 从服务器中获取数据时必须传的参数Page页数
     */
    private int page = 1;
    /**
     * 要求获取多少条数据
     */
    private int limit = 10;
    /**
     * 要求返回哪个类别下的topic
     */
    private String tab;
    /**
     * 是否渲染所有出现的 markdown 格式文本
     */
    private String mdrender = "true";

    public String getMdrender() {
        return mdrender;
    }

    /**
     * 重置Page页数为第一页
     */
    public void restorePage(){
        this.page = 1;
    }

    public int getPage() {
        return page;
    }

    public int getLimit() {
        return limit;
    }

    public String getMyTab() {
        return tab;
    }

    /**
     * 设置Tab
     * @param Tab 主题分类，取值范围是{‘all’，‘ask’，‘share’，‘job’，‘good’},
     *             意义：all为全部；ask为问答；share为分享；job为招聘；good为精华
     */
    public void setTab(String Tab){
        this.tab = Tab;
    };

    public void addPage(){
        this.page = this.page + 1;
    }

    public BaseFragments(){}

    public abstract String getFragmentTitle();

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        EventBus.getDefault().unregister(this);
        super.onStop();
    }

    /**
     * 跳转到用户详情界面的实际业务逻辑
     * @param loginName 用户名
     */
    public void goToMyInfo(String loginName) {
        Intent intent = new Intent(getActivity(), MyActivity.class);
        intent.putExtra("loginName", loginName);
        startActivity(intent);
    }

    /**
     * 跳转到话题详情界面的实际业务逻辑
     * @param id 话题的ID
     */
    public void goToTopicDetail(String id) {
        Intent intent = new Intent(getActivity(), TopicDetailActivity.class);
        intent.putExtra("TopicId", id);
        startActivity(intent);
    }
}
